//
//  GesturePasswordCell.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/1.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class GesturePasswordCell: UICollectionViewCell {

    private lazy var centerBall = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        buildUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //item背景色
    public var itemBackGoundColor:UIColor?
    
    public var gestureSelected:Bool? {
        didSet {
            if gestureSelected! {
                //选中
                layer.borderWidth = 0
                centerBall.isHidden = false
                backgroundColor = itemBackGoundColor
            }else {
                //未选中
                layer.borderWidth = 1
                centerBall.isHidden = true
                backgroundColor = UIColor.white
            }
        }
    }
    
    public var itemCenterBallColor:UIColor? {
        didSet {
            centerBall.backgroundColor = itemCenterBallColor
        }
    }
}

extension GesturePasswordCell {
    
    private func buildUI() -> Void {
        layer.cornerRadius = bounds.height / 2
        layer.masksToBounds = true
        layer.borderWidth = 1
        layer.borderColor = UIColor.init(displayP3Red: 129/255.0, green: 129/255.0, blue: 129/255.0, alpha: 1).cgColor
        
        let dotW = bounds.width * 0.45
        centerBall.frame = CGRect(x: 0, y: 0, width: dotW, height: dotW)
        centerBall.center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
        centerBall.layer.cornerRadius = centerBall.bounds.height / 2
        centerBall.layer.masksToBounds = true
        addSubview(centerBall)
    }
}
